From c2b3ae42f64f72fa0888f2914f6ea860de792539 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 8 Apr 2005 18:18:55 +0000 Subject: [PATCH] snapshot (at the moment: - registry format should be changed, an additional field is needed read doc/substvar_filling.txt for more info) --- dh_ocaml | 49 +++++++++++++++++++++++----------------- doc/registry_feeding.txt | 10 ++++++++ doc/substvar_filling.txt | 20 ++++++++++++++++ ocaml-md5sums.ml | 26 +++++++++++++-------- 4 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 doc/substvar_filling.txt diff --git a/dh_ocaml b/dh_ocaml index 390b1cc1..9262daf0 100755 --- a/dh_ocaml +++ b/dh_ocaml @@ -23,10 +23,7 @@ # # TODO check how dh_ocaml work when multiple binary packages are being built -# TODO for libraries: add proper dependencies on ocaml (and findlib?) -# TODO for binaries: check if package is shipping any bytecode binaries (head -1 -# should be enough) and add proper dependencies on ocaml -# TODO complete POD documentation +# TODO add proper dependencies on ocaml (and findlib?) # TODO check if dh_ocaml md5sums calculation works with -pack -ed units (e.g. # Foo.Bar) @@ -64,18 +61,26 @@ dh_ocaml is a debhelper program that is responsible for generating the ${ocaml:Depends} substitutions and adding them to substvars files. It will also add a postinst and prerm script if required. -The program will look at ocaml objects (files matching *.cm[ao]) shipped by your -package. From them, dh_ocaml uses ocamlobjinfo for collecting information about -ocaml modules (or units, in ocamlobjinfo terminology) defined and used by your -package. Collected information will be used both for extracting dependencies -information from the local ocaml md5sums registry (stored in -/var/lib/ocaml/md5sums/MD5SUMS) and for creating libfoo-ocaml-dev.md5sums entry -for the registry. - -Dependencies information will be used for filling the ${ocaml:Depends} -subtitution while .md5sums entry will be installed in /var/lib/ocaml/md5sums/. -If such an entry gets installed, postinst and prerm script will also be created -in order to update the registry at package install/removal time. +dh_ocaml acts both on ocaml library packages (having name libXXX-ocaml-dev) and +on packages shipping ocaml bytecode non-custom binaries (i.e. executables +interpreted by /usr/bin/ocamlrun). + +On ocaml library packages dh_ocaml will firstly look at ocaml objects (files +matching *.cm[ao]) shipped by the package. Then, dh_ocaml uses ocamlobjinfo on +them for collecting information about ocaml modules (or units, in ocamlobjinfo +terminology) defined and used by them. Information about defined units will be +used to automatically create the ocaml md5sums registry entry for your package, +e.g. /var/lib/ocaml/md5sums/libXXX-ocaml-dev.md5sums. dh_ocaml will also take +care of creating autoscripts (postrm and postinst) which update the global +system registry (/var/lib/ocaml/md5sums/MD5SUMS) with the shipped entry. +Information about imported units will instead be used as keys in the ocaml +md5sums registry for retrieving dependency information for the package. Those +information will then be used to fill the ${ocaml:Depends} substvar. + +On non-library packages, dh_ocaml tries to guess the ocaml objects corresponding +to shipped bytecode binaries and extract from them information about imported +units. Extracted information will then be used for filling the ${ocaml:Depends} +as discussed for the library case. =head1 CONFORMS TO @@ -93,7 +98,7 @@ sub find_ocaml_bc_binaries($) { foreach my $bin (@binaries) { my $line = `/usr/bin/head -1 $bin` or next; chomp $line; - push @bc_binaries, $line if $line eq $ocaml_magic_line; + push @bc_binaries, $bin if $line eq $ocaml_magic_line; } return @bc_binaries; } @@ -106,9 +111,11 @@ sub fill_ocaml_depends($$) { open DEPS, "< $fname" or die "Can't open $fname"; while (my $line = ) { chomp $line; - my ($dep_package, $dep_version) = split /\s+/, $line; - next unless $dep_package and $dep_version; - addsubstvar($package, "ocaml:Depends", $dep_package, ">= $dep_version"); + if ($line =~ /^\s*(\S+)\s+(\S+)\s*$/) { + addsubstvar($package, "ocaml:Depends", $1, ">= $2"); + } elsif ($line =~ /^\s*(\S+)\s*$/) { + addsubstvar($package, "ocaml:Depends", $1); + } } close DEPS; } @@ -141,7 +148,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) { complex_doit "> $ocamldeps"; foreach my $bin (@binaries) { # try to find .cmo of bc binaries my $guess = basename($bin) . ".cm[ao]"; - complex_doit("/usr/bin/find . -type f -name '$guess' >> $ocamldeps"); + complex_doit("/usr/bin/find . -type f -name '$guess' >> $objlist"); } complex_doit("$ocaml_md5sums $flags dep < $objlist > $ocamldeps"); } diff --git a/doc/registry_feeding.txt b/doc/registry_feeding.txt index 0c753b4f..be199b88 100644 --- a/doc/registry_feeding.txt +++ b/doc/registry_feeding.txt @@ -1,6 +1,16 @@ entries which should be pre-fed into the registry at ocaml package installation time: +- ocaml-nox-VERSION + registry entry can be generated with: + + ocaml-md5sums compute --package ocaml-nox-3.08.3 /usr/lib/ocaml/3.08.3/stdlib.cma + +- ocaml-VERSION + registry entry can be generated with: + + dpkg -L ocaml ocaml | grep .cma | ocaml-md5sums compute --package ocaml-3.08.3 + 71f888453b0f26895819460a72f07493 Pervasives ocaml-nox-3.08.3 3.08.3-3 TODO entry for ocaml-3.08.3 diff --git a/doc/substvar_filling.txt b/doc/substvar_filling.txt new file mode 100644 index 00000000..ac36c670 --- /dev/null +++ b/doc/substvar_filling.txt @@ -0,0 +1,20 @@ +informal description of the ${ocaml:Depends} filling algorithm +- delsubstvar("ocaml:Depends") +- if pkgname is "libfoo-ocaml-dev" + (handle also "ocaml:Depends" for "libfoo-ocaml" if it does exist) + - find all installed .cm[ao] + - run "ocaml-md5sums dep" on them + - let D be the set of resulting dependencies + - foreach d in D of the form + - addsubstvar("ocaml:Depends", "libfoo-ocaml-dev", dev-dependency, version) + - if exists package "libfoo-ocaml" and exists runtime-dependency + - addsubstvar("ocaml:Depends", "libfoo-ocaml", runtime-dependency, version) +- if pkgname is something else + - find all installed ocaml bytecode binaries + - guess corresponding .cm[ao] + - run "ocaml-md5sums dep" on them + - let D be the set of resulting dependencies + - foreach d in D of the form + - if exists runtime-dependency + - addsubstvar("ocaml:Depends", pkgname, runtime-dependency, version) + diff --git a/ocaml-md5sums.ml b/ocaml-md5sums.ml index e32d2768..c268a1e5 100644 --- a/ocaml-md5sums.ml +++ b/ocaml-md5sums.ml @@ -37,6 +37,7 @@ let unit_name_line_RE = let md5sum_line_RE = Str.regexp "^[ \t]*\\([a-f0-9]+\\)[ \t]+\\([a-zA-Z0-9_]+\\)[ \t]*$" let blanks_RE = Str.regexp "[ \t]+" +let ignorable_line_RE = Str.regexp "^[ \t]*\\(#.*\\)?" let md5sums_ext_RE = Str.regexp (sprintf "^.*%s$" (Str.quote md5sums_ext)) (** {2 Argument parsing} *) @@ -52,15 +53,15 @@ let action = ref None let usage_msg = "Use and maintain system registry of ocaml md5sums\n" ^ "Usage:\n" - ^ " ocaml-md5sum compute --package --version [options] file ...\n" - ^ " ocaml-md5sum dep --package --version [options] file ...\n" + ^ " ocaml-md5sum compute --package [option ...] file ...\n" + ^ " ocaml-md5sum dep --package [option ...] file ...\n" ^ " ocaml-md5sum update\n" ^ "Options:" let cmdline_spec = [ "--package", Arg.Set_string pkg_name, "set package name (required by compute and dep actions)"; "--version", Arg.Set_string pkg_version, - "set package version (required by compute and dep actions)"; + "set package version"; "--dump-info", Arg.Set_string dump_info_to, "dump ocamlobjinfo to file"; "--load-info", Arg.Set_string load_info_from, @@ -172,11 +173,16 @@ let unit_info fnames = dump_info ~defined ~imported !dump_info_to; (defined, imported) +type registry_callback = + md5sum:string -> unit_name:string -> package:string -> ?version:string -> + unit -> + unit + (** iter a function over the entries of a registry file * @param f function to be executed for each entries, it takes 4 labeled - * arguments: ~md5sum ~unit_name ~package ~version + * arguments: ~md5sum ~unit_name ~package ?version * @param fname file containining the registry *) -let iter_registry f fname = +let iter_registry (f: registry_callback) fname = info ("processing registry " ^ fname); let lineno = ref 0 in iter_file @@ -184,7 +190,9 @@ let iter_registry f fname = incr lineno; (match Str.split blanks_RE line with | [ md5sum; unit_name; package; version ] -> - f ~md5sum ~unit_name ~package ~version + f ~md5sum ~unit_name ~package ~version () + | [ md5sum; unit_name; package ] -> f ~md5sum ~unit_name ~package () + | _ when Str.string_match ignorable_line_RE line 0 -> () | _ -> warning (sprintf "ignoring registry entry (%s, line %d)" fname !lineno))) @@ -197,7 +205,7 @@ let iter_registry f fname = let parse_registry fname = let registry = Hashtbl.create 1024 in iter_registry - (fun ~md5sum ~unit_name ~package ~version -> + (fun ~md5sum ~unit_name ~package ?(version = "") () -> Hashtbl.replace registry (unit_name, md5sum) (package, version)) fname; registry @@ -241,7 +249,7 @@ let update () = && ((Unix.stat fname).Unix.st_kind = Unix.S_REG) then iter_registry - (fun ~md5sum ~unit_name ~package ~version -> + (fun ~md5sum ~unit_name ~package ?(version = "") () -> fprintf registry "%s %s %s %s\n" md5sum unit_name package version) fname done @@ -264,7 +272,7 @@ let main () = | Some "update" -> update () | Some action -> let package, version = !pkg_name, !pkg_version in - if (package = "" || version = "") then die_usage (); + if package = "" then die_usage (); let objects = match !objects with | [] when !load_info_from = "" -> read_stdin () -- 2.30.2